<?php
class RM_Reviews extends RM_Model_Multilingual
{
    protected $_name = 'rm_reviews';
    //protected $_units = 'rm_amenities_units';


    /**
     * return the amenities row and join with the amenities language details
     * @param <type> $iso 
     */
    public function getAll(){
        $sql = "
            SELECT *
            FROM $this->_name
            ";
        return $this->_getBySQL($sql);
    }

    /**
     * return the amenities row and join with the amenities language details
     * @param string $id
     */
    public function getAllUnits(){
        $sql = "
            SELECT *
            FROM $this->_name LEFT JOIN $this->_units ON
            $this->_name.id = $this->_units.amenity_id
            ";
        return $this->_getBySQL($sql);
    }

    /**
     * return the amenities row and join with the amenities language details
     * @param string $id
     */
    public function getAmenitiesDetails($id){
        $sql = "
            SELECT *
            FROM $this->_name LEFT JOIN $this->_units ON
            $this->_name.id = $this->_units.amenity_id
            WHERE $this->_name.id = '$id'
            ";
        return $this->_getBySQL($sql);
    }

    /**
     * Get the amenities by the unit ID
     * @param string $unitID
     */
    public function getbyUnit($unitID, $iso){
        
        $allAmenities = $this->getAllUnits()->toArray();
        $amenities = array();
        foreach($allAmenities as $row){
                if ($row['unit_id']==$unitID){
                    $amenities[] = array("id"=>$row['amenity_id'],"name"=>$row[$iso],"icon_url"=>$row['icon_url'],"info_url"=>$row['info_url']);
                }
        }
        return $amenities;
    }
}